package com.hmall.api.interceptor;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;

public class UserInfoRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 获取登录用户
        Long userId = UserContext.getUser();
        if(userId == null){
            // 如果为空则直接跳过
            return;
        }
        // 如果不为空则放入请求头中，传递给下游微服务
        requestTemplate.header("user-info", userId.toString());
    }
}
